//
//  BaseViewController.m
//  LOL_JewelBox
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "BaseViewController.h"
#import "Singleon.h"
#import "AFNetworking.h"
#import "NetworkingViewController.h"
@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];

    // 2.设置网络状态改变后的处理
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        // 当网络状态改变了, 就会调用这个block
        switch (status) {
            case AFNetworkReachabilityStatusUnknown: // 未知网络
                [Singleon shareSingleton].statu = @"unknown_internet";
                break;

            case AFNetworkReachabilityStatusNotReachable: // 没有网络(断网)
                if (![[Singleon shareSingleton].statu isEqualToString:@"lost_internet"]) {

                    NetworkingViewController *net = [[NetworkingViewController alloc] init];
                    [self.navigationController pushViewController:net animated:YES];
                    [net release];




                    [Singleon shareSingleton].statu = @"lost_internet";
                }
                break;

            case AFNetworkReachabilityStatusReachableViaWWAN: // 手机自带网络
                if (![[Singleon shareSingleton].statu isEqualToString:@"mobile_internet"]) {
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"正在使用手机流量,建议切换到WIFI" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                    [alert show];
                    [alert release];
                    [Singleon shareSingleton].statu = @"mobile_internet";
                }
                break;

            case AFNetworkReachabilityStatusReachableViaWiFi: // WIFI
                [Singleon shareSingleton].statu = @"wifi_internet";
                break;
        }
    }];

    // 3.开始监控
    [mgr startMonitoring];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
